package com.sinosoft.cnmuseum.servlets;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;

import com.sinosoft.cnmuseum.dao.MbXtglJsglDao;
import com.sinosoft.cnmuseum.utils.PageUtil;
import com.sinosoft.cnmuseum.utils.Status;
import com.sinosoft.commontools.annotated.rquestMethod;
import com.sinosoft.commontools.annotated.rquestMethod.ReqMode;
import com.sinosoft.commontools.record.Record;

public class MbXtglCjrServlet {
	  private static Logger logger = Logger.getLogger(MbXtglCjrServlet.class);

	@rquestMethod(MethodNote = ReqMode.All)
	public Record getCjr(HttpServletRequest request, HttpServletResponse response, Record data){
		Record result = new Record();
		try {
			MbXtglJsglDao dao = new MbXtglJsglDao();
			  int pagenumber = data.getIntValue(Status.PAGENUMBER);// 获取当前页
			  int pagesize = data.getIntValue(Status.PAGESIZE);// 获取每页多少条数据
			  String countsql = "select count(yh.zdbh) as count from mb_xtgl_yhxx yh, mb_xtgl_ryjsfp js where " 
					  + " yh.zdbh=js.rybm and js.jsbm='cj' " ;
			  String sql = "select yh.* from mb_xtgl_yhxx yh, mb_xtgl_ryjsfp js where " 
					  + " yh.zdbh=js.rybm and js.jsbm='cj' " ;
			  String ordersql = " order by zdbh asc ";
			  String limitsql = " limit ";
			  logger.info("CSQL:" + countsql);
			  List<Record> countlist = dao.getBySql(countsql);
			  int total = countlist.get(0).getIntValue("count");
			  PageUtil page = new PageUtil(pagenumber, pagesize, total);
			  limitsql += page.getStart()+","+pagesize;
			  logger.info("SQL:" + sql+ordersql+limitsql);
			  List<Record> list = dao.getBySql(sql+ordersql+limitsql);
			  // 组装数据
			  result.add(Status.ROWS, list);
			  result.add(Status.TOTAL, total);
			  result.add(Status.PAGENUMBER, pagenumber);
			  result.add(Status.PAGESIZE, pagesize);
			  result.add(Status.PAGETOTAL, page.getPagetotal());
			  // 返回接口调用成功标识
			  result.add(Status.SATUS,Status.OK);
		} catch (Exception e) {
			  // 返回接口调用失败标识
			  result.add(Status.SATUS,Status.FAILED);
			  // 返回接口调用失败信息，需要自己添加
			  result.add(Status.MSG,"查询失败！");
		}
		return result;
	}

}
